<div [@routerTransition]>
    <div class="content d-flex flex-column flex-column-fluid">
        <sub-header [title]="'Course' | localize" [description]="'CourseManage' | localize">
            <div role="actions"></div>
        </sub-header>


        <div [class]="containerClass">
            <div class="card card-custom gutter-b">
                <div class="card-body">
                    <div class="row">
                        <form class="horizontal-form" autocomplete="off">
                            <div class="m-form m-form--label-align-right">
                                <div class="row align-items-center mb-4">
                                    <div class="col-3">
                                        <div class="form-group m-form__group align-items-center">
                                            <label>{{l('name')}} / {{l('itemId')}}</label>
                                            <div class="input-group">
                                                <input [(ngModel)]="filterText" name="filterText" autoFocus
                                                    class="form-control m-input" (keyup.enter)="getCourses()"
                                                    [placeholder]="l('SearchWithThreeDot')" type="text">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-2">
                                        <div class="form-group m-form__group align-items-center">
                                            <label>&nbsp;</label>
                                            <div class="input-group">
                                                <button type="button" class="btn btn-primary"
                                                    [buttonBusy]="primengTableHelper.isLoading" (click)="getCourses()">
                                                    <i class="la la-refresh"></i>
                                                    {{l("search")}}
                                                </button>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-7 text-right">
                                        <button type="button" (click)="setTraining()" class="btn btn-primary blue">
                                            <i class="fa fa-plus"></i> {{l("SetTraining")}}</button>
                                        <button type="button" (click)="deleteBatch()" class="btn btn-primary blue">
                                            <i class="icon-piliangcaozuo"></i> {{l("deleteBatch")}}</button>
                                        <button type="button" (click)="creatCourse()" class="btn btn-primary blue">
                                            <i class="fa fa-plus"></i> {{l("add")}}{{l("Course")}}</button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="row align-items-center">
                        <!--<Primeng-Datatable-Start>-->
                        <div class="primeng-datatable-container" [busyIf]="primengTableHelper.isLoading">
                            <!-- resizableColumns="primengTableHelper.resizableColumns" -->
                            <p-table #dataTable (onLazyLoad)="getCourses($event)" [value]="primengTableHelper.records"
                                [rows]="primengTableHelper.defaultRecordsCountPerPage" [(selection)]="coursePublishList"
                                [paginator]="false" [lazy]="true"
                                [resizableColumns]="primengTableHelper.resizableColumns"
                                [responsive]="primengTableHelper.isResponsive">
                                <ng-template pTemplate="header">
                                    <tr>
                                        <th
                                            *ngIf="isGranted('Pages.Tenant.Training.Delete')||isGranted('Pages.Tenant.Training.Edit')">
                                            {{l('Actions')}}</th>
                                        <th>
                                            <p-tableHeaderCheckbox></p-tableHeaderCheckbox>
                                        </th>
                                        <th>{{l('RecordId')}}</th>

                                        <th>{{l('name')}}</th>

                                        <th>{{l('tags')}}</th>

                                        <th>{{l('courseNo')}}</th>

                                        <th>{{l('description')}}</th>
                                    </tr>
                                </ng-template>
                                <ng-template pTemplate="body" let-record let-i="rowIndex">
                                    <tr [pSelectableRow]="record" [attr.trid]="record.id">
                                        <td
                                            *ngIf="isGranted('Pages.Tenant.Training.Delete')||isGranted('Pages.Tenant.Training.Edit')">
                                            <div class="btn-group dropdown" dropdown normalizePosition>
                                                <button class="dropdown-toggle btn btn-sm btn-primary"
                                                    data-toggle="dropdown" dropdownToggle aria-haspopup="true"
                                                    aria-expanded="false">
                                                    <i class="fa fa-cog"></i>
                                                    <span class="caret"></span> {{l("Actions")}}
                                                </button>
                                                <ul class="dropdown-menu" *dropdownMenu>
                                                    <li *ngIf="isGranted('Pages.Tenant.Training.Edit')">
                                                        <a (click)="editCourse(record)"
                                                            class="icon-bianji dropdown-item">{{l('Edit')}}</a>
                                                    </li>
                                                    <li *ngIf="isGranted('Pages.Tenant.Training.Delete')">
                                                        <a (click)="deleteCourse(record)"
                                                            class="icon-icon-test dropdown-item">{{l('Delete')}}</a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </td>
                                        <td>
                                            <p-tableCheckbox [value]="record"></p-tableCheckbox>
                                        </td>
                                        <td> {{transIndex(i)}}</td>
                                        <td>
                                            <span>{{record.name}}</span>
                                        </td>

                                        <td>
                                            <span *ngFor="let tag of record.courseTags"
                                                class="label label-dark label-inline">
                                                {{tag.name}}
                                            </span>
                                            <span *ngIf="!record.courseTags||record.courseTags.length==0">
                                                {{EmptyTdText}}
                                            </span>
                                        </td>
                                        <td>{{record.courseNo}}</td>
                                        <td>{{record.description}}</td>
                                    </tr>
                                </ng-template>
                                <ng-template pTemplate="emptymessage" let-records>
                                    <tr *ngIf="primengTableHelper.records">
                                        <td colspan="6">
                                            <img class="emptymessage"
                                                src="/assets/common/images/placeholder/couponHolder.png" />
                                        </td>
                                    </tr>
                                </ng-template>
                            </p-table>
                            <div class="primeng-paging-container">
                                <p-paginator [rows]="primengTableHelper.defaultRecordsCountPerPage" #paginator
                                    (onPageChange)="getCourses($event)"
                                    [totalRecords]="primengTableHelper.totalRecordsCount"
                                    [rowsPerPageOptions]="primengTableHelper.predefinedRecordsCountPerPage">
                                </p-paginator>
                                <span class="total-records-count">
                                    {{l('TotalRecordsCount', primengTableHelper.totalRecordsCount)}}
                                </span>
                            </div>
                        </div>
                        <!--<Primeng-Datatable-End>-->
                    </div>
                </div>
            </div>
        </div>
        <courseModal #courseModal (modalSave)="getCourses()"></courseModal>
        <trainingModal #trainingModal (modalSave)="getCourses()"></trainingModal>
        <!-- 实例化modal -->
        <!-- <createOrEditTrainingModal #CreateOrEditTrainingModal (modalSave)="getCoupons()"></createOrEditTrainingModal> -->
    </div>
</div>